//
//  LGNewFeatureController.m
//  微博
//
//  Created by MS on 15-12-5.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGNewFeatureController.h"
#import "LGNewFeatrueCell.h"
@interface LGNewFeatureController ()

@property (nonatomic,weak) UIPageControl  * pageControl;

@end

@implementation LGNewFeatureController

static NSString * ID = @"Cell";


-(instancetype)init
{
   
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
    
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    
    layout.minimumLineSpacing = 0;
    
    layout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
    
    return [super initWithCollectionViewLayout:layout];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.collectionView.backgroundColor = [UIColor greenColor];
    
    //分页
    self.collectionView.pagingEnabled = YES;
    //取消弹性
    self.collectionView.bounces = NO;
    self.collectionView.showsHorizontalScrollIndicator=NO;
    
   // collectionViewz注册cell
   [self.collectionView registerClass:[LGNewFeatrueCell class] forCellWithReuseIdentifier:ID];
    
    [self setUpPageControl];
    
}

-(void)setUpPageControl
{
    UIPageControl * pageControl = [[UIPageControl alloc] init];

    pageControl.center = CGPointMake(self.view.width * 0.5, self.view.height);
    pageControl.height = 30;
    pageControl.y = self.view.height - pageControl.height ;
    pageControl.numberOfPages = 4;
    pageControl.pageIndicatorTintColor = [UIColor blackColor];
    pageControl.currentPageIndicatorTintColor = [UIColor redColor];
    [self.view addSubview:pageControl];
    
    self.pageControl  = pageControl;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    int page = scrollView.contentOffset.x/scrollView.bounds.size.width + 0.5;
    self.pageControl.currentPage = page;
    
    
}



-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 4;
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    LGNewFeatrueCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    CGFloat ScreenW = [UIScreen mainScreen].bounds.size.width;
    
     // 拼接图片名称 3.5 320 480
    NSString * imageName = [NSString stringWithFormat:@"new_feature_%ld",indexPath.row+1];
    
    if (ScreenW>480) {// 5 , 6 , 6 plus
        
         imageName = [NSString stringWithFormat:@"new_feature_%ld-568h",indexPath.row+1];
    }
    
    cell.image = [UIImage imageNamed:imageName];
    
    [cell setIndexPath:indexPath count:4];
    
    return cell;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark <UICollectionViewDataSource>



@end
